package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.home.domain.HomeInformation;
import com.ruoyi.home.service.IHomeInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资讯信息管理Controller
 *
 * @author ruoyi
 * @date 2024-03-20
 */
@Anonymous
@RestController
@RequestMapping("/home/information")
public class HomeInformationController extends BaseController
{
    @Autowired
    private IHomeInformationService homeInformationService;

    /**
     * 查询资讯信息管理列表
     */
//    @PreAuthorize("@ss.hasPermi('home:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeInformation homeInformation)
    {
        startPage();
        List<HomeInformation> list = homeInformationService.selectHomeInformationList(homeInformation);
        return getDataTable(list);
    }

    /**
     * 导出资讯信息管理列表
     */
//    @PreAuthorize("@ss.hasPermi('home:information:export')")
    @Log(title = "资讯信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeInformation homeInformation)
    {
        List<HomeInformation> list = homeInformationService.selectHomeInformationList(homeInformation);
        ExcelUtil<HomeInformation> util = new ExcelUtil<HomeInformation>(HomeInformation.class);
        util.exportExcel(response, list, "资讯信息管理数据");
    }

    /**
     * 获取资讯信息管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('home:information:query')")
    @GetMapping(value = "/{informationId}")
    public AjaxResult getInfo(@PathVariable("informationId") Long informationId)
    {
        return success(homeInformationService.selectHomeInformationByInformationId(informationId));
    }

    /**
     * 新增资讯信息管理
     */
//    @PreAuthorize("@ss.hasPermi('home:information:add')")
    @Log(title = "资讯信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeInformation homeInformation)
    {
        return toAjax(homeInformationService.insertHomeInformation(homeInformation));
    }

    /**
     * 修改资讯信息管理
     */
//    @PreAuthorize("@ss.hasPermi('home:information:edit')")
    @Log(title = "资讯信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeInformation homeInformation)
    {
        return toAjax(homeInformationService.updateHomeInformation(homeInformation));
    }

    /**
     * 删除资讯信息管理
     */
//    @PreAuthorize("@ss.hasPermi('home:information:remove')")
    @Log(title = "资讯信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{informationIds}")
    public AjaxResult remove(@PathVariable Long[] informationIds)
    {
        return toAjax(homeInformationService.deleteHomeInformationByInformationIds(informationIds));
    }
}
